package com.example.administrator.rxjavadiydemo.presenter;

import android.app.Dialog;
import android.content.Context;

import com.example.administrator.rxjavadiydemo.bean.HomeBean;
import com.example.administrator.rxjavadiydemo.interfaces.IMain_getData;
import com.example.administrator.rxjavadiydemo.model.Model_Main;
import com.example.administrator.rxjavadiydemo.util.FragmentDialog;
import com.example.administrator.rxjavadiydemo.view_activity.MainActivity;
import com.example.library.utils.L;

/**
 * Created by lw on 2017/11/21.
 */

public class Presenter_Main {
    private MainActivity mMainActivity;
    private final Model_Main mModel_main;
    private FragmentDialog mFragmentDialog;

    public Presenter_Main(MainActivity mainActivity){
        mModel_main = new Model_Main();
        mMainActivity = mainActivity;
    }

    public void getData(){
        mModel_main.getData(new IMain_getData() {
            @Override
            public void completed(HomeBean homeBean) {
                L.e("lw"+homeBean.toString());
            }

            @Override
            public void onError(String error) {

            }

            @Override
            public void before() {
                mFragmentDialog = new FragmentDialog();
                if(!mFragmentDialog.isAdded()){
                    mFragmentDialog.show(mMainActivity.getSupportFragmentManager(),"tag");
                }

            }

            @Override
            public void after() {
                if(mFragmentDialog!=null){
                    mFragmentDialog.dismiss();
                }
            }
        });


    }





    public void onDestroy() {
        mModel_main.onDestroy();
    }


}
